package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ParkingCard;
import com.ruoyi.service.IParkingCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车卡Controller
 * 
 * @author dongdong
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/parking/parkingCard")
public class ParkingCardController extends BaseController
{
    @Autowired
    private IParkingCardService parkingCardService;

    /**
     * 查询停车卡列表
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingCard parkingCard)
    {
        startPage();
        List<ParkingCard> list = parkingCardService.selectParkingCardList(parkingCard);
        return getDataTable(list);
    }

    /**
     * 导出停车卡列表
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:export')")
    @Log(title = "停车卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingCard parkingCard)
    {
        List<ParkingCard> list = parkingCardService.selectParkingCardList(parkingCard);
        ExcelUtil<ParkingCard> util = new ExcelUtil<ParkingCard>(ParkingCard.class);
        util.exportExcel(response, list, "停车卡数据");
    }

    /**
     * 获取停车卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parkingCardService.selectParkingCardById(id));
    }

    /**
     * 新增停车卡
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:add')")
    @Log(title = "停车卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingCard parkingCard)
    {
        return toAjax(parkingCardService.insertParkingCard(parkingCard));
    }

    /**
     * 修改停车卡
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:edit')")
    @Log(title = "停车卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingCard parkingCard)
    {
        return toAjax(parkingCardService.updateParkingCard(parkingCard));
    }

    /**
     * 删除停车卡
     */
    @PreAuthorize("@ss.hasPermi('parking:parkingCard:remove')")
    @Log(title = "停车卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(parkingCardService.deleteParkingCardById(id));
    }
}
